import os
import shutil

"""  
    假设两个文件夹有类似的目录结构:  
    src1/000/images, src1/001/images    
    src1/000/maps, src1/001/maps    
    我希望将src2的maps复制到src1中  
"""
def copy_images(source_folder, destination_folder):
    # 确保目标文件夹存在
    if not os.path.exists(destination_folder):
        print("Target folder doesn't exist")
        return

        # 遍历源文件夹中的所有文件夹
    for folder in os.listdir(source_folder):
        # 如果目标路径已经存在且是目录，则合并内容
        src_folder = os.path.join(source_folder, folder)
        dst_folder = os.path.join(destination_folder, folder)

        if os.path.exists(dst_folder) and os.path.isdir(dst_folder):
            # 对于文件夹中的所有文件/文件夹
            for sub_folder in os.listdir(src_folder):
                # 将源文件夹复制到目标位置
                sub_src_folder = os.path.join(src_folder, sub_folder)
                sub_dst_folder = os.path.join(dst_folder, sub_folder)
                shutil.copytree(sub_src_folder, sub_dst_folder, dirs_exist_ok=True)
                # shutil.move(os.path.join(src_folder, sub_folder), dst_folder)
            # print(f'Moved: {src_folder} to {dst_folder}')
                print(f'Copied: {sub_src_folder} to {sub_dst_folder}')

        # 示例调用
if __name__ == '__main__':
    source_folder = './copy_test/src1'
    destination_folder = './copy_test/src0'
    copy_images(source_folder, destination_folder)